/**
 * 
 */
package net.ddns.heroli.service;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.gzheroli.cache.SpringRedisCache;
import cn.com.gzheroli.core.common.service.CommonService;
import cn.com.gzheroli.core.common.service.HeroService;
import net.ddns.heroli.pojo.TBAttachment;

/**  
* 类名: AttachMentServiceImpl  
* 描述: TODO(这里用一句话描述这个类的作用)  
* 作者: 李长荣 lichang_20011@163.com  
* 日期: 2017年12月19日  下午8:38:58
*@version V1.0  
*    
*/
@Service("attachMentService")
public class AttachMentServiceImpl implements AttachMentService{
	private static final Logger logger = LoggerFactory.getLogger(AttachMentServiceImpl.class);
	@Autowired
	private CommonService commonService;
	@Autowired
    private SpringRedisCache cache;
	@Autowired
	private HeroService heroService;
	public List<Map<String,Object>> getAttachment(Map paraMap ){
		//String sql="select a.ID,a.BUSINESS_KEY,a.TABLE_NAME,a.REAL_PATH,a.EXT_NAME,bu.REAL_NAME, a.USER_ID,a.REMARK,a.TYPE,a.FILE_NAME,a.CREATE_DATE,a.TAG ";
		String sql="select a.ID,a.BUSINESS_KEY,a.TABLE_NAME,a.REAL_PATH,a.EXT_NAME, a.USER_ID,a.REMARK,a.TYPE,a.FILE_NAME,a.CREATE_DATE,a.TAG ";
		//sql=sql+" from T_B_ATTACHMENT a,T_S_BASE_USER bu ";
		sql=sql+" from T_B_ATTACHMENT a ";
		//sql=sql+" where bu.ID=a.USER_ID and bu.STATUS='1' ";
		sql=sql+" where 1=1 ";
		if(paraMap.containsKey("id"))
			sql=sql+" and ID=#{id}";
		if(paraMap.containsKey("businessKey"))
			sql=sql+" and BUSINESS_KEY=#{businessKey}";
		if(paraMap.containsKey("fileName")&&paraMap.get("fileName")!=null&&!paraMap.get("fileName").toString().trim().equals(""))
			sql=sql+" and FILE_NAME=#{fileName}";
		if(paraMap.containsKey("type"))
			sql=sql+" and TYPE=#{type}";
		if(paraMap.containsKey("remark"))
			sql=sql+" and REMARK=#{remark}";
		if(paraMap.containsKey("tag"))
			sql=sql+" and TAG=#{tag}";
		List<Map<String,Object>> attachments=commonService.findForJdbc(sql+" order by a.CREATE_DATE desc",  paraMap);
		return attachments;
	}
	public List<TBAttachment> getAttachmentList(Map paraMap ){
		//String sql="select a.ID,a.BUSINESS_KEY,a.TABLE_NAME,a.REAL_PATH,a.EXT_NAME,bu.REAL_NAME, a.USER_ID,a.REMARK,a.TYPE,a.FILE_NAME,a.CREATE_DATE,a.MAX_WIDTH,a.TAG ";
		String sql="select a.ID,a.BUSINESS_KEY,a.TABLE_NAME,a.REAL_PATH,a.EXT_NAME,a.USER_ID,a.REMARK,a.TYPE,a.FILE_NAME,a.CREATE_DATE,a.MAX_WIDTH,a.TAG ";
		sql=sql+" from T_B_ATTACHMENT a";
		sql=sql+" where 1=1 ";
		//sql=sql+" from T_B_ATTACHMENT a,T_S_BASE_USER bu ";
		//sql=sql+" where bu.ID=a.USER_ID and bu.STATUS='1' ";
		if(paraMap.containsKey("id"))
			sql=sql+" and a.ID=#{id}";
		if(paraMap.containsKey("businessKey"))
			sql=sql+" and a.BUSINESS_KEY=#{businessKey}";
		if(paraMap.containsKey("fileName")&&paraMap.get("fileName")!=null&&!paraMap.get("fileName").toString().trim().equals(""))
			sql=sql+" and a.FILE_NAME=#{fileName}";
		if(paraMap.containsKey("type"))
			sql=sql+" and a.TYPE=#{type}";
		if(paraMap.containsKey("remark"))
			sql=sql+" and a.REMARK=#{remark}";
		if(paraMap.containsKey("tag")){
			if(paraMap.get("tag")!=null&&!paraMap.get("tag").toString().trim().equals(""))
				sql=sql+" and a.TAG=#{tag}";
			else
				sql=sql+" and a.TAG is not null ";
		}
			
		List<TBAttachment> attachments=commonService.findByQueryString(sql+" order by a.CREATE_DATE desc", TBAttachment.class, paraMap);
		return attachments;
	}
}
